package com.example.test_1;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class ActivityChuanCan1 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chuan_can1);

    }

    public void tiaB(View view) {
        //方式一：putExtra
/*        Intent intent = new Intent(this, ActivityChuanCan2.class);
        intent.putExtra("name","王五");
        intent.putExtra("age",90);
        startActivity(intent);
        */


        //方式二：通过构建一个bundle对象,获取也不一样了，进入chuancan2
        Intent intent = new Intent(this, ActivityChuanCan2.class);
        Bundle bundle = new Bundle();
        bundle.putString("name","张三");
        bundle.putInt("age",78);
        intent.putExtras(bundle);
        //startActivity(intent);
        //第一步跳转页面使用startActivityForResult，
        // 第二步在chuancan2中添加一个返回按钮并添加一个点击事件，返回的时候调用setResult
        startActivityForResult(intent,100);

    }

    //第三步，如何接收数据，需要重写一个onactivity result

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode==RESULT_OK && requestCode == 100){
            String result = data.getStringExtra("result");
            Toast.makeText(this, result, Toast.LENGTH_SHORT).show();
        }
    }
}